package com.example.uiclassassignments.Activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.uiclassassignments.R;
import com.example.uiclassassignments.tools.ListViewAdapter;
import com.example.uiclassassignments.tools.ListViewItemData;

import java.util.ArrayList;

public class ListViewActivity extends AppCompatActivity {
    private ArrayList<ListViewItemData> mListViewData;
    private ListView mListview4Consume;

    private  ListViewItemData createListViewItemData(int order,String date, String money){
        ListViewItemData listViewItemData = new ListViewItemData();
        listViewItemData.order = order;
        listViewItemData.date = date;
        listViewItemData.money = money;
        return  listViewItemData;
    }
    protected void initData() {
        mListViewData = new ArrayList<ListViewItemData>();
        mListViewData.add(createListViewItemData(1,"1-01","10"));
        mListViewData.add(createListViewItemData(2,"1-10","13"));
        mListViewData.add(createListViewItemData(3,"1-13","15"));
        mListViewData.add(createListViewItemData(4,"1-16","16"));
    }
    private void initListHeader() {
        ViewGroup headerView = (ViewGroup) LayoutInflater.from(this).inflate(
                R.layout.listview_activity_list_item,
                mListview4Consume,
                false);
        TextView tvId = (TextView) headerView.getChildAt(0);
        TextView tvBusId = (TextView) headerView.getChildAt(1);
        TextView tvCapacity = (TextView) headerView.getChildAt(2);
        tvId.setText("序号");
        tvBusId.setText("消费 日期");
        tvCapacity.setText("消费金额");
        mListview4Consume.addHeaderView(headerView);
    }
    private void initListFooter() {
        ViewGroup footerView = (ViewGroup) LayoutInflater.from(this).inflate(
                R.layout.listview_activity_foot_item,
                mListview4Consume,
                false);
        mListview4Consume.addFooterView(footerView);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);
        mListview4Consume = findViewById(R.id.myListView);
        initData();
        initListHeader();
        initListFooter();
        ListAdapter adapter = new ListViewAdapter(this);
        mListview4Consume.setAdapter(adapter);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }
}
